package com.ruoyi.web.controller.market.extend;

import java.util.List;
import java.util.Map;

import cn.hutool.core.util.StrUtil;
import com.ruoyi.db.domain.CountInfo;
import com.ruoyi.db.model.excle.CountUvInfoExcel;
import com.ruoyi.db.model.param.CountUvInfoParam;
import com.ruoyi.extend.service.ICountInfoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.db.domain.CountUvInfo;
import com.ruoyi.extend.service.ICountUvInfoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.wapper.CountUvInfoWapper;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * uvCountInfoController
 * 
 * @author ruoyi
 * @date 2022-10-27
 */
@Controller
@RequestMapping("/extend/uvCountInfo")
public class CountUvInfoController extends BaseController
{
    private String prefix = "extend/uvCountInfo";

    @Autowired
    private ICountUvInfoService countUvInfoService;
    @Autowired
    private ICountInfoService countInfoService;

    @RequiresPermissions("extend:uvCountInfo:view")
    @GetMapping()
    public String uvCountInfo()
    {
        return prefix + "/uvCountInfo";
    }

    /**
     * 查询uvCountInfo列表
     */
//    @RequiresPermissions("extend:uvCountInfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CountUvInfo countUvInfo)
    {
        startPage();
        List<Map<String, Object>> mapList = countUvInfoService.selectCountUvInfoListMap(countUvInfo);
        mapList = new CountUvInfoWapper(mapList).wrap();
        return getDataTable(mapList);
    }

    /**
     * 导出uvCountInfo列表
     */
//    @RequiresPermissions("extend:uvCountInfo:export")
    @Log(title = "uvCountInfo", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CountUvInfo countUvInfo)
    {

        CountInfo countInfo = countInfoService.selectCountInfoById(String.valueOf(countUvInfo.getCountId()));
        String title = StrUtil.format("{}_{}", countInfo.getChannelName(), countInfo.getDateInfo());

        List<CountUvInfoExcel> list = countUvInfoService.selectCountUvInfoList(countUvInfo);
        ExcelUtil<CountUvInfoExcel> util = new ExcelUtil<CountUvInfoExcel>(CountUvInfoExcel.class);
        return util.exportExcel(list, title);
    }

    /**
     * 新增uvCountInfo
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存uvCountInfo
     */
    @RequiresPermissions("extend:uvCountInfo:add")
    @Log(title = "uvCountInfo", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CountUvInfo countUvInfo)
    {
        return toAjax(countUvInfoService.insertCountUvInfo(countUvInfo));
    }

    /**
     * 修改uvCountInfo
     */
    @RequiresPermissions("extend:uvCountInfo:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        CountUvInfo countUvInfo = countUvInfoService.selectCountUvInfoById(id);
        mmap.put("countUvInfo", countUvInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存uvCountInfo
     */
    @RequiresPermissions("extend:uvCountInfo:edit")
    @Log(title = "uvCountInfo", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CountUvInfo countUvInfo)
    {
        return toAjax(countUvInfoService.updateCountUvInfo(countUvInfo));
    }

    /**
     * 删除uvCountInfo
     */
    @RequiresPermissions("extend:uvCountInfo:remove")
    @Log(title = "uvCountInfo", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(countUvInfoService.deleteCountUvInfoByIds(ids));
    }
}
